﻿namespace Lari.Services.Implementation
{
    public class LariService
    {
/*
        protected int? CurrtenUser
        {
            get
            {
                if (OperationContext.Current != null &&
                    OperationContext.Current.IncomingMessageHeaders.FindHeader("UserID", "CustomHeader") == 1)
                {
                    return OperationContext.Current.IncomingMessageHeaders.GetHeader<int>("UserID", "CustomHeader");
                }
                return null;
            }
        }
*/


        //protected void OpenConnection()
        //{
        //    if (dbContext != null && dbContext)
        //    if (db != null && db.Connection.State == ConnectionState.Closed)
        //        db.Connection.Open();
        //}

        //protected IHMSCache CreateCacheClient()
        //{
        //    ChannelFactory<IHMSCache> fac = new ChannelFactory<IHMSCache>("Client_CacheManegment");
        //    return fac.CreateChannel();

        //}
        //protected void Close(IHMSCache client)
        //{

        //    if (client != null && (IClientChannel)client != null && ((IClientChannel)client).State != CommunicationState.Closed)
        //    {
        //        ((IClientChannel)client).Close();
        //    }

        //}
        //protected void Abort(IHMSCache client)
        //{

        //    if (client != null && (IClientChannel)client != null && ((IClientChannel)client).State != CommunicationState.Closed)
        //    {
        //        ((IClientChannel)client).Abort();
        //    }

        //}
//        protected List<T> GetDataFromCache<T>()
//        {

//            List<T> retValue = null;

//#if CACHE_ENABLE
//            Console.WriteLine("Geting data from cache for " + typeof(T).ToString());
//            IHMSCache client = null;
//            try
//            {
//                client = CreateCacheClient();

//                switch (typeof(T).ToString())
//                {
//                    case "HMS.Services.Contract.Data.Access":
//                        retValue = client.GetAccesses() as List<T>;
//                        break;
//                    case "HMS.Services.Contract.Data.BloodGroup":
//                        retValue = client.GetBloodGroups() as List<T>;
//                        break;
//                    case "HMS.Services.Contract.Data.Country":
//                        retValue = client.GetCountries() as List<T>;
//                        break;
//                    case "HMS.Services.Contract.Data.Department":
//                        retValue = client.GetDepartments() as List<T>;
//                        break;
//                    case "HMS.Services.Contract.Data.Designation":
//                        retValue = client.GetDesignations() as List<T>;
//                        break;
//                    case "HMS.Services.Contract.Data.Employee":
//                        retValue = client.GetEmployees() as List<T>;
//                        break;
//                    case "HMS.Services.Contract.Data.Facility":
//                        retValue = client.GetFacilities() as List<T>;
//                        break;
//                    case "HMS.Services.Contract.Data.Gender":
//                        retValue = client.GetGenders() as List<T>;
//                        break;
//                    case "HMS.Services.Contract.Data.MaritalStatus":
//                        retValue = client.GetMaritalStatuses() as List<T>;
//                        break;
//                    case "HMS.Services.Contract.Data.Religion":
//                         retValue = client.GetReligions() as List<T>;
//                        break;
//                    case "HMS.Services.Contract.Data.Role":
//                        retValue = client.GetRoles() as List<T>;;
//                        break;
//                    case "HMS.Services.Contract.Data.State":
//                        retValue = client.GetStates() as List<T>;;
//                        break;
//                    case "HMS.Services.Contract.Data.Title":
//                        retValue = client.GetTitles() as List<T>;;
//                        break;


//                }
//                Close(client);


//            }
//            catch (Exception ex)
//            {
//                Abort(client);
//                ErrorHandler.HandelNonWCFError(ExceptionCode.CACHE.GET_T_FROM_CACHE_FAILED, ex, "CacheManagement for Type "+typeof(T).ToString());
//            }
//#endif

//            return retValue;
//        }
    }
}